    //
//  gameViewController.m
//  BallGame
//
//  Created by 沈 冬冬 on 11-11-1.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "gameViewController.h"
#import "B_CellVIew.h";
#import "Constants.h"
#import "B_Scene.h";
#import "Main.h"
#import "Global.h"
#import "SceneDefines.h"
#import "SwfImageParser.h"
#import "UIDefine.h"
#import "McView.h"
#import "BBSceneController.h"
#import "BBInputViewController.h"
#import "EAGLView.h"
#import "BGSwfMaker.h"
#import "GLScene.h"

@implementation GameViewController
@synthesize scene,scene2;
@synthesize mainUI,sceneController,gameViewController;

- (void)loadView 
{
	self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, gameWidth,gameHeight)];
	self.view.backgroundColor = [UIColor blackColor];
	
	//总的场景控制器 opengl部分
	sceneController = [BBSceneController sharedSceneController];
	
	BBInputViewController * anInputController = [[BBInputViewController alloc] initWithNibName:nil bundle:nil];
	sceneController.inputController = anInputController;
	//[anInputController release];
	
	//初始化 EAGLView
	EAGLView * glView = [[EAGLView alloc] initWithFrame:self.view.bounds];
	sceneController.inputController.view = glView;
	sceneController.openGLView = glView;
	[glView release];
	[self.view addSubview:sceneController.inputController.view];
		
	//加载场景，初始化UI
	[BGSwfMaker getSingleSwfMaker:@"SpaceRocksAtlas"];			//加载图片
	
	[sceneController loadScene];
	[sceneController startScene];

	/*//uikit动画播放逻辑测试
	McView *test = [[McView alloc] initWithFrame:CGRectMake(0, 0, 250, 250)];
	[test setFileName:@"role1_81_250_250_16.png"];
	[self.view addSubview:test];
	[test setBackgroundColor:[UIColor clearColor]];
	 */
	
	mainUI = [Main alloc];
	[self.view addSubview:mainUI.view];			//主界面
	[Global setGloabalController:self];	

}

- (void)viewDidLoad {
    [super viewDidLoad];
}

-(void)showParticularScene:(int) sceneIndex
{
	if (battleScene == battleScene) 
	{
		[mainUI.view setHidden:YES];
		
		/*
		if (self.scene == nil)
		{
			self.scene = [B_Scene alloc];
			[self.view addSubview:self.scene.view];
		}
		 */

		 if (self.scene2 == nil)
		{
			self.scene2 = [GLScene alloc];
			[self.scene2 initGLScene];
		}
		
	}
	else if(battleScene == battleScene) 
	{
		
	}
	else {
		;
	}

	
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Overriden to allow any orientation.
	return NO;
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc. that aren't in use.
}

- (void)viewDidUnload {
	
    [super viewDidUnload];
	// Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)dealloc {
	[mainUI release];
	[scene release];
	[gameViewController release];
	
    [super dealloc];
}


@end
